/**************************************************************************/
/*! 
    @file     projectconfig.h
    @author   K. Townsend (microBuilder.eu)

    @section LICENSE

    Software License Agreement (BSD License)

    Copyright (c) 2010, microBuilder SARL
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
    1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
    2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
    3. Neither the name of the copyright holders nor the
    names of its contributors may be used to endorse or promote products
    derived from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**************************************************************************/

#ifndef _PROJECTCONFIG_H_
#define _PROJECTCONFIG_H_

#include "lpc134x.h"
#include "sysdefs.h"

/**************************************************************************
    PIN USAGE
    -----------------------------------------------------------------------
    This table tries to give an indication of which GPIO pins and 
    peripherals are used by the available drivers and SW examples.  Only
    dedicated GPIO pins available on the LPC1343 Reference Board are shown
    below.  Any unused peripheral blocks like I2C, SSP, ADC, etc., can
    also be used as GPIO if they are available.


    Roger Zimmermann's LPC1343 CB0001_p2 PCB
    -----------------------------------------------------------------------
                PORT 0        PORT 1        PORT 2          PORT 3 
                ============  ============  ============    ======
                          11            11            11    
                012345678901  012345678901  012345678901    0123
    /RESET      x...........  ............  ............    ....    
    /HWB        .x..........  ............  ............    ....    
    LEDs        ..x.........  ............  ..........xx    ....    LED3 (yellow), LED1 (red), LED2 (green)
    USB         ...x..x.....  ............  ............    ....    Vbus, Connect, n's board
    I2C         ....xx......  ............  xxxxxx......    ....    SCL, SDA, I2C0..5 enables
    Charger     .......x...x  ............  ............    ....    CHR_CON (Charger connected = 1)
    RC Servo    ........x...  ............  ............    xxx.    SRV0 data, SEL_A, SEL_B, SEL_C
    SW Debugger x........xx.  ...x........  ............    ....    /RESET, SWO, SWCLK, SWDIO
	ADC			............  xxx.........  ............    ....    I_BAT, V_BAT, AUDIO
	Encoders    ............  ....xxxx....  ............    ....    ENC1A, ENC1B, ENC2A, ENC2B
	Motor       ............  ........xxxx  ............    ....    /MOTOR_EN, PWM_M1, PWM_M2, /MOTOR_SD
	GPIO        ............  ............  ......xxxx..    ....    BUMP2, BUMP1, SW1, SW2
    +5V enable  ............  ............  ............    ...x    ENABLE = 1    

 
                TIMERS                    SSP     ADC         UART
                ======================    ===     =======     ====
                16B0  16B1  32B0  32B1    0       0 1 2 3     0

    Motor PWM   .     X     .     .       .       . . . .     .
    Charger PWM .     .     X     .       .       . . . .     .
    USB         .     .     .     X       .       . . . .     .
    INTERFACE   .     .     .     .       .       . . . .     .
    -----------------------------------------------------------------------

 
    [1]  PMU uses 32-bit Timer 0 for SW wakeup from deep-sleep.  This timer
         can safely be used by other peripherals, but may need to be
         reconfigured when you wakeup from deep-sleep.
    [2]  INTERFACE can be configured to use either USBCDC or UART

 **************************************************************************/


/*=========================================================================
    FIRMWARE VERSION SETTINGS
    -----------------------------------------------------------------------*/
    #define CFG_FIRMWARE_VERSION_MAJOR            (0)
    #define CFG_FIRMWARE_VERSION_MINOR            (8)
    #define CFG_FIRMWARE_VERSION_REVISION         (5)  /*4H IO board*/
/*=========================================================================*/


/*=========================================================================
    CORE CPU SETTINGS
    -----------------------------------------------------------------------

    CFG_CPU_CCLK    Value is for reference only.  'core/cpu/cpu.c' must
                    be modified to change the clock speed, but the value
                    should be indicated here since CFG_CPU_CCLK is used by
                    other peripherals to determine timing.

    -----------------------------------------------------------------------*/
    #define CFG_CPU_CCLK                (72000000)  // 1 tick = 13.88nS
/*=========================================================================*/


/*=========================================================================
    SYSTICK TIMER
    -----------------------------------------------------------------------

    CFG_SYSTICK_DELAY_IN_US   The number of microseconds between each tick
                              of the systick timer.

    DDS_DIVISOR               Number of passes through SYSTICK interrupt in
                              1 second.  (Reciprical of 20us).
    -----------------------------------------------------------------------*/
    #define CFG_SYSTICK_DELAY_IN_US     (20)
		#define DDS_DIVISOR                 (50000)
/*=========================================================================*/


/*=========================================================================
    ON-BOARD LED
    -----------------------------------------------------------------------

    CFG_LED_PORT              The port for the on board LED
    CFG_LED_PIN               The pin for the on board LED
    CFG_LED_ON                The pin state to turn the LED on (0 = low, 1 = high)
    CFG_LED_OFF               The pin state to turn the LED off (0 = low, 1 = high)

    -----------------------------------------------------------------------*/
    #define CFG_LED_PORT                (2)
    #define CFG_LED_PIN                 (10)
    #define CFG_LED_ON                  (1)
    #define CFG_LED_OFF                 (0)

    #define CFG_LED3_PORT               (2)
    #define CFG_LED4_PORT               (2)
    #define CFG_LED5_PORT               (0)
    #define CFG_LED3_PIN                (10)
    #define CFG_LED4_PIN                (11)
    #define CFG_LED5_PIN                (2)


/*=========================================================================
    ON-BOARD PWM
    -----------------------------------------------------------------------

    CFG_PWM_PORT              The port for the PWM
    CFG_PWM_MAT0              Pin number of MAT0 output
    CFG_PWM_MAT1              Pin number of MAT1 output

    -----------------------------------------------------------------------*/
    #define CFG_PWM_PORT                (1)
    #define CFG_PWM_MAT0                (9)
    #define CFG_PWM_MAT1                (10)
    #define CFG_SHUTDOWN_PORT           (1)
    #define CFG_SHUTDOWN_PIN            (11)
    #define CFG_AMPSHUTDOWN_PORT        (1)
    #define CFG_AMPSHUTDOWN_PIN         (11)
    #define CFG_AMPENABLE_PORT          (1)
    #define CFG_AMPENABLE_PIN           (8)
    

/*=========================================================================
    ON-BOARD GPIO
    -----------------------------------------------------------------------

    CFG_ENABLE_PORT           The port for the PWM
    CFG_ENABLE                Pin number of ENABLE output

    -----------------------------------------------------------------------*/
    #define CFG_ENABLE_PORT             (3)
    #define CFG_ENABLE_PIN              (3)
    #define CFG_ENABLE_ON               (1)
    #define CFG_ENABLE_OFF              (0)
		


/*=========================================================================*/




/*=========================================================================
    USB
    -----------------------------------------------------------------------

    CFG_USBHID                If this field is defined USB HID support will
                              be included.  Currently uses ROM-based USB HID
    CFG_USBCDC                If this field is defined USB CDC support will
                              be included, with the USB Serial Port speed
                              set to 115200 BPS by default
    CFG_USBCDC_BAUDRATE       The default TX/RX speed.  This value is used 
                              when initialising USBCDC, and should be a 
                              standard value like 57600, 9600, etc.
    CFG_USBCDC_INITTIMEOUT    The maximum delay in milliseconds to wait for
                              USB to connect.  Must be a multiple of 10!

    NOTE: CFG_USBHID =        ~0.5 KB Flash and 36 bytes SRAM (-Os)
    NOTE: CFG_USBCDC =        ~4.0 KB Flash and 272 bytes SRAM (-Os)
    -----------------------------------------------------------------------*/
    // #define CFG_USBHID
    #define CFG_USBCDC
    #define CFG_USBCDC_BAUDRATE         (230400)
    #define CFG_USBCDC_INITTIMEOUT      (5000)
/*=========================================================================*/


/*=========================================================================
    PRINTF REDIRECTION
    -----------------------------------------------------------------------

    CFG_PRINTF_UART           Will cause all printf statements to be 
                              redirected to UART
    CFG_PRINTF_USBCDC         Will cause all printf statements to be
                              redirect to USB Serial
    CFG_PRINTF_NEWLINE        This should be either "\r\n" for Windows or
                              "\n" for *nix

    Note: If no printf redirection definitions are present, all printf
    output will be ignored, though this will also save ~350 bytes flash.

    NOTE: PRINTF Support =    ~350 bytes Flash (-Os)
    -----------------------------------------------------------------------*/
    #define CFG_PRINTF_USBCDC
    #define CFG_PRINTF_NEWLINE          "\r\n"
/*=========================================================================*/


/*=========================================================================
    COMMAND LINE INTERFACE
    -----------------------------------------------------------------------

    CFG_INTERFACE             If this field is defined the UART or USBCDC
                              based command-line interface will be included
    CFG_INTERFACE_MAXMSGSIZE  The maximum number of bytes to accept for an
                              incoming command
    CFG_INTERFACE_PROMPT      The command prompt to display at the start
                              of every new data entry line
    CFG_INTERFACE_SILENTMODE  If this is set to 1 only text generated in
                              response to commands will be send to the
                              output buffer.  The command prompt will not
                              be displayed and incoming text will not be
                              echoed back to the output buffer (allowing
                              you to see the text you have input).  This
                              is normally only desirable in a situation
                              where another MCU is communicating with 
                              the LPC1343.
    CFG_INTERFACE_ENABLEIRQ   If this is set to 1 the IRQ pin will be
                              set high when a command starts executing
                              and will go low when the command has
                              finished executing or the LCD is not busy.
                              This allows another device to know when a
                              new command can safely be sent.
    CFG_INTERFACE_IRQPORT     The gpio port for the IRQ/busy pin
    CFG_INTERFACE_IRQPIN      The gpio pin number for the IRQ/busy pin

    NOTE:                     The command-line interface will use either
                              USB-CDC or UART depending on whether
                              CFG_PRINTF_UART or CFG_PRINTF_USBCDC are 
                              selected.
    -----------------------------------------------------------------------*/
    #define CFG_INTERFACE
    #define CFG_INTERFACE_MAXMSGSIZE    (256)
    #define CFG_INTERFACE_PROMPT        "TC>> "
    #define CFG_INTERFACE_SILENTMODE    (0)
    #define CFG_INTERFACE_ENABLEIRQ     (1)
    #define CFG_INTERFACE_IRQPORT       (2)
    #define CFG_INTERFACE_IRQPIN        (0)
/*=========================================================================*/


/*=========================================================================
    PWM SETTINGS
    -----------------------------------------------------------------------

    CFG_PWM                     If this is defined, a basic PWM driver
                                will be included using 16-bit Timer 1 and
                                Pin 1.9 (MAT0) for the PWM output.  In
                                order to allow for a fixed number of
                                pulses to be generated, some PWM-specific
                                code is required in the 16-Bit Timer 1
                                ISR.  See "core/timer16/timer16.c" for
                                more information.
    CFG_PWM_DEFAULT_PULSEWIDTH  The default pulse width in ticks
    CFG_PWM_DEFAULT_DUTYCYCLE   The default duty cycle in percent

    DEPENDENCIES:               PWM output requires the use of 16-bit
                                timer 1 and pin 1.9 (CT16B1_MAT0).
    -----------------------------------------------------------------------*/
    // #define CFG_PWM
    #define CFG_PWM_DEFAULT_PULSEWIDTH  (CFG_CPU_CCLK / 1000)
    #define CFG_PWM_DEFAULT_DUTYCYCLE   (50)
/*=========================================================================*/



/*=========================================================================
    EEPROM
    -----------------------------------------------------------------------

    CFG_I2CEEPROM             If defined, drivers for the onboard EEPROM
                              will be included during build
    CFG_I2CEEPROM_SIZE        The number of bytes available on the EEPROM

    -----------------------------------------------------------------------*/
    #define CFG_I2CEEPROM
    #define CFG_I2CEEPROM_SIZE          (4096)
/*=========================================================================*/


/*=========================================================================
    EEPROM MEMORY MAP
    -----------------------------------------------------------------------
    EEPROM is used to persist certain user modifiable values to make
    sure that these changes remain in effect after a reset or hard
    power-down.  The addresses in EEPROM for these various system
    settings/values are defined below.  The first 256 bytes of EEPROM
    are reserved for this (0x0000..0x00FF).

    CFG_EEPROM_RESERVED       The last byte of reserved EEPROM memory

          EEPROM Address (0x0000..0x00FF)
          ===============================
          0 1 2 3 4 5 6 7 8 9 A B C D E F
    000x  . . . . . . . . . . . . . . . .   
    001x  . . . . . . . . . . . . . . . .   
    002x  . . . . . . . . . . . . . . . .   
    003x  . . . . . . . . . . . . . . . .
    004x  . . . . . . . . . . . . . . . .
    005x  . . . . . . . . . . . . . . . .
    006x  . . . . . . . . . . . . . . . .
    007x  . . . . . . . . . . . . . . . .
    008x  . . . . . . . . . . . . . . . .
    009x  . . . . . . . . . . . . . . . .
    00Ax  . . . . . . . . . . . . . . . .
    00Bx  . . . . . . . . . . . . . . . .
    00Cx  . . . . . . . . . . . . . . . .
    00Dx  . . . . . . . . . . . . . . . .
    00Ex  . . . . . . . . . . . . . . . .
    00Fx  . . . . . . . . . . . . . . . .

    -----------------------------------------------------------------------*/
    #define CFG_EEPROM_RESERVED                 (0x00FF)              // Protect first 256 bytes of memory
//    #define CFG_EEPROM_CHIBI_IEEEADDR           (uint16_t)(0x0000)    // 8
//    #define CFG_EEPROM_CHIBI_SHORTADDR          (uint16_t)(0x0009)    // 2
//    #define CFG_EEPROM_UART_SPEED               (uint32_t)(0x0020)    // 4
/*=========================================================================*/






/*=========================================================================
  CONFIG FILE VALIDATION
  -------------------------------------------------------------------------
  Basic error checking to make sure that incompatible defines are not 
  enabled at the same time, etc.

  =========================================================================*/

#if defined CFG_PRINTF_USBCDC && defined CFG_PRINTF_UART
  #error "CFG_PRINTF_UART or CFG_PRINTF_USBCDC cannot both be defined at once"
#endif

#if defined CFG_PRINTF_USBCDC && !defined CFG_USBCDC
  #error "CFG_PRINTF_CDC requires CFG_USBCDC to be defined as well"
#endif

#if defined CFG_USBCDC && defined CFG_USBHID
  #error "Only one USB class can be defined at a time (CFG_USBCDC or CFG_USBHID)"
#endif

#endif
